package com.yonyou.pmclouds.workstopreport.process;

import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.workstopreport.entity.WorkStopVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import yonyou.bpm.rest.request.AssignInfoItem;
import yonyou.bpm.rest.request.Participant;

@Component
@Slf4j
public class WorkStopAssignInfoItemProcess implements SingleProcessor<WorkStopVO> {
    @Override
    public void process(WorkStopVO vo, WorkStopVO orig) throws BusinessException {
        if(isSame(vo)){
            vo.setCanApprove(true);
        }
    }

    public boolean isSame(WorkStopVO workStopVO){
        String creator = workStopVO.getCreator();
        if(workStopVO.assignInfo == null){
            return false;
        }

        AssignInfoItem[] assignInfoItems = workStopVO.assignInfo.getAssignInfo().getAssignInfoItems();
        for(AssignInfoItem assignInfoItem : assignInfoItems){
            Participant[] participants = assignInfoItem.getParticipants();
            for(Participant participant : participants){
                if(creator.equals(participant.getId())){
                    return true;
                }
            }
        }
        return false;
    }
}
